package com.control;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.po.Jiatiao;
import com.po.User;
import com.service.UserService;

@Controller
@RequestMapping("/jiatiao")
public class JiatiaoControl  extends BaseControl{
	@Autowired
	private UserService us;
	
	@RequestMapping("/add")
	public String add(@RequestParam("content") String content){
		User u = (User) session.getAttribute("user");
		if(us.addJiatiao(u.getId(), content)){
			session.setAttribute("user", us.getById(u.getId()));
			return "user";
			//return "success";
		}
		
		return "error";
	}

	public String getAll(){
		
		List<Jiatiao> js = us.getJiatiaoAll();
		session.setAttribute("jiatiaos", js);
		return "js";
	}
	@RequestMapping("/getMyWorks")
	public String getMyWorks(){
		User u = (User) session.getAttribute("user");
		List<Jiatiao> jts = us.getWorksById(u);
		session.setAttribute("myWorks", jts);
		return "myWorks";
	}
	@RequestMapping("/setOk")
	public String setOk(@RequestParam("jid")int id){
		if(us.setOk(id)){
			return "jt/jiatiao/getMyWorks";
		}else{
			return "error";
		}
	}
	@RequestMapping("/setBack")
	public String setBack(@RequestParam("jid")int id){
		if(us.setBack(id)){
			return "jt/jiatiao/getMyWorks";
		}else{
			return "error";
		}
	}
}
